package com.tonann.app.controller;

import com.tonann.app.domain.AppSensorRecord;
import com.tonann.app.service.IAppSensorRecordService;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.core.page.TableDataInfo;
import com.tonann.common.enums.BusinessType;
import com.tonann.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 运行记录Controller
 *
 * @author tonann
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/app/sensorRecord")
public class AppSensorRecordController extends BaseController {
    @Autowired
    private IAppSensorRecordService appSensorRecordService;

    /**
     * 查询运行记录列表
     */
    @PreAuthorize("@ss.hasPermi('app:sensorRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppSensorRecord appSensorRecord) {
        startPage();
        List<AppSensorRecord> list = appSensorRecordService.selectAppSensorRecordList(appSensorRecord);
//        Map<String, Object> map = new HashMap<>();
//        if (appSensorRecord.getSensorId() != null) {
//            map.put("sensorId", appSensorRecord.getSensorId());
//        }
//        List<AppSensorRecord> list =  appSensorRecordMongoService.findAllMap(map,AppSensorRecord.class);
        return getDataTable(list);
//        mongoPage = appSensorRecordMongoService.getPage(mongoPage, map);
//        TableDataInfo tableDataInfo = new TableDataInfo(mongoPage.getList(), (int) mongoPage.getTotal());
//        return tableDataInfo;
    }

//    /**
//     * 导出运行记录列表
//     */
//    @PreAuthorize("@ss.hasPermi('app:sensorRecord:export')")
//    @Log(title = "运行记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, AppSensorRecord appSensorRecord) {
//        List<AppSensorRecord> list = appSensorRecordService.selectAppSensorRecordList(appSensorRecord);
//        ExcelUtil<AppSensorRecord> util = new ExcelUtil<AppSensorRecord>(AppSensorRecord.class);
//        util.exportExcel(response, list, "运行记录数据");
//    }

    /**
     * 获取运行记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:sensorRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return AjaxResult.success(appSensorRecordService.selectAppSensorRecordByRecordId(recordId));
    }

    /**
     * 新增运行记录
     */
    @PreAuthorize("@ss.hasPermi('app:sensorRecord:add')")
    @Log(title = "运行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppSensorRecord appSensorRecord) {
        return toAjax(appSensorRecordService.insertAppSensorRecord(appSensorRecord));
    }

    /**
     * 修改运行记录
     */
//    @PreAuthorize("@ss.hasPermi('app:sensorRecord:edit')")
//    @Log(title = "运行记录", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody AppSensorRecord appSensorRecord) {
//        appSensorRecord.setUpdateBy(getUsername());
////        return toAjax(appSensorRecordMongoService.up)
////        return toAjax(appSensorRecordService.updateAppSensorRecord(appSensorRecord));
//    }

    /**
     * 删除运行记录
     */
//    @PreAuthorize("@ss.hasPermi('app:sensorRecord:remove')")
//    @Log(title = "运行记录", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{recordIds}")
//    public AjaxResult remove(@PathVariable Long[] recordIds) {
//        return toAjax(appSensorRecordService.deleteAppSensorRecordByRecordIds(recordIds));
//    }
}
